using System.Text.Json;
using System.Text.Json.Serialization;
using ZR.Model;

namespace ZR.Model.System.Dto
{
    /// <summary>
    /// 雷达初始化请求对象
    /// </summary>
    public class WindLidarInitRequestDto
    {
        /// <summary>
        /// 命令类型
        /// </summary>
        public string CommandType { get; set; } = "init";

        /// <summary>
        /// 命令数据
        /// </summary>
        public object CommandData { get; set; } = null;
    }

    /// <summary>
    /// 雷达初始化响应对象
    /// </summary>
    public class WindLidarInitResponseDto
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        [JsonPropertyName("success")]
        public bool Success { get; set; }

        /// <summary>
        /// 消息（可能是字符串或数字）
        /// </summary>
        [JsonPropertyName("message")]
        public JsonElement Message { get; set; }

        /// <summary>
        /// 详细信息（可能是字符串或数字）
        /// </summary>
        [JsonPropertyName("detail")]
        public JsonElement Detail { get; set; }

        /// <summary>
        /// 雷达初始化动作执行结果（可能是布尔值或数字）
        /// </summary>
        [JsonPropertyName("data")]
        public JsonElement Data { get; set; }

        /// <summary>
        /// 获取消息字符串
        /// </summary>
        public string GetMessage()
        {
            if (Message.ValueKind == JsonValueKind.String)
                return Message.GetString() ?? "0";
            else if (Message.ValueKind == JsonValueKind.Number)
                return Message.GetInt32().ToString();
            else if (Message.ValueKind == JsonValueKind.True || Message.ValueKind == JsonValueKind.False)
                return Message.GetBoolean().ToString();
            else if (Message.ValueKind == JsonValueKind.Null)
                return "0";
            return Message.ToString();
        }

        /// <summary>
        /// 获取详细信息字符串
        /// </summary>
        public string GetDetail()
        {
            if (Detail.ValueKind == JsonValueKind.String)
                return Detail.GetString() ?? "0";
            else if (Detail.ValueKind == JsonValueKind.Number)
                return Detail.GetInt32().ToString();
            else if (Detail.ValueKind == JsonValueKind.True || Detail.ValueKind == JsonValueKind.False)
                return Detail.GetBoolean().ToString();
            else if (Detail.ValueKind == JsonValueKind.Null)
                return "0";
            return Detail.ToString();
        }

        /// <summary>
        /// 获取数据布尔值
        /// </summary>
        public bool GetData()
        {
            if (Data.ValueKind == JsonValueKind.True)
                return true;
            else if (Data.ValueKind == JsonValueKind.False)
                return false;
            else if (Data.ValueKind == JsonValueKind.Number)
                return Data.GetInt32() != 0;
            return false;
        }
    }

    /// <summary>
    /// 雷达初始化查询结果
    /// </summary>
    public class WindLidarInitResultDto
    {
        /// <summary>
        /// 初始化是否成功
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 响应消息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 详细信息
        /// </summary>
        public string Detail { get; set; }

        /// <summary>
        /// 查询时间
        /// </summary>
        public DateTime QueryTime { get; set; }

        /// <summary>
        /// 初始化状态描述
        /// </summary>
        public string StatusDescription { get; set; }
    }

    /// <summary>
    /// 开始采集请求对象
    /// </summary>
    public class WindLidarStartRequestDto
    {
        /// <summary>
        /// 类型：DBS 或 PPI
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 最大范围（DBS 和 PPI 都需要）
        /// </summary>
        public int? MaxRange { get; set; }

        /// <summary>
        /// 距离分辨率（DBS 和 PPI 都需要）
        /// </summary>
        public int? RangeResolution { get; set; }

        /// <summary>
        /// 方位角起始（PPI 模式需要）
        /// </summary>
        public int? AzimuthStart { get; set; }

        /// <summary>
        /// 方位角结束（PPI 模式需要）
        /// </summary>
        public int? AzimuthEnd { get; set; }

        /// <summary>
        /// 仰角（PPI 模式需要）
        /// </summary>
        public int? Elevation { get; set; }

        /// <summary>
        /// 角度分辨率（PPI 模式需要）
        /// </summary>
        public int? AngleResolution { get; set; }
    }
}
